package pacmandfs;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class Solution {
	/* Head ends here */
	private static Stack<Integer> path_x = new Stack<Integer>(), path_y = new Stack<Integer>();
	private static List<Integer> explore_x = new ArrayList<Integer>(), explore_y = new ArrayList<Integer>();
	private static boolean found = false;
	static void dfs(int x, int y, int pacman_x, int pacman_y, int food_x, int food_y, char[][] grid) {
		if(pacman_x >= x && pacman_y >= y)
			return;
		if(grid[pacman_x][pacman_y] != '-' && grid[pacman_x][pacman_y] != '.')
			return;
		path_x.push(pacman_x);
		path_y.push(pacman_y);
		explore_x.add(pacman_x);
		explore_y.add(pacman_y);
		if(grid[pacman_x][pacman_y] == '.') {
			found = true;
			return;
		}
		grid[pacman_x][pacman_y] = 'v';
		dfs(x, y, pacman_x + 1, pacman_y, food_x, food_y, grid);
		if(found)
			return;
		dfs(x, y, pacman_x, pacman_y + 1, food_x, food_y, grid);
		if(found)
			return;
		dfs(x, y, pacman_x, pacman_y - 1, food_x, food_y, grid);
		if(found)
			return;
		dfs(x, y, pacman_x - 1, pacman_y, food_x, food_y, grid);
		if(found)
			return;
		path_x.pop();
		path_y.pop();
	}
	static void dfs(int x, int y, int pacman_x, int pacman_y, int food_x, int food_y, String [] grid) {
		char[][] cGrid = new char[x][y];
		for(int i = 0; i < x; i++)
			cGrid[i] = grid[i].toCharArray();
		cGrid[pacman_x][pacman_y] = '-';
		dfs(x, y, pacman_x, pacman_y, food_x, food_y, cGrid);
		System.out.println(explore_x.size());
		for(int i = 0; i < explore_x.size(); i++)
			System.out.println(explore_x.get(i) + " " + explore_y.get(i));
		System.out.println(path_x.size() - 1);
		for(int i = 0; i < path_x.size(); i++)
			System.out.println(path_x.get(i) + " " + path_y.get(i));
	}
	/* Tail starts here */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int pacman_x = in.nextInt();
		int pacman_y = in.nextInt();

		int food_x = in.nextInt();
		int food_y = in.nextInt();

		int x = in.nextInt();
		int y = in.nextInt();

		String grid[] = new String[x];

		for(int i = 0; i < x; i++) {
			grid[i] = in.next();
		}
		in.close();
		
		dfs( x, y, pacman_x, pacman_y, food_x, food_y, grid);
	}
}
